<?php
namespace Home\Controller;
use Think\Controller;
class SetdataController extends CommonController {
    public function index(){
    	// var_dump($_SESSION['id']);
      $res=M('user')->find($_SESSION['id']);
     $this->assign('res',$res);
     //  var_dump($res);
       $this->display();
    }


   // 修改资料方法
    public function update(){
        
        if (D('user')->checkNewNickname(I('post.nickname'))) {

        	  $arr=array(
                  'error'=>'1',
                  'info'=>'昵称已被使用！'
        	  	);
        	  echo json_encode($arr);
        	  exit;
        }elseif (D('user')->checkNewemail(I('post.email'))) {
        	 $arr=array(
                  'error'=>'1',
                  'info'=>'邮箱已被使用！'
        	  	);
        	  echo json_encode($arr);
        	  exit;
        }


        $data = I('post.');
        
        if(M('user')->where(array('id'=>$_SESSION['id']))->save($data)){
        	$_SESSION['nickname']=I('post.nickname');
        	$arr=array(
                  'error'=>'0',
                  'info'=>'恭喜你修改成功'
        	  	);
    	  	echo json_encode($arr);
    	  	exit;
        }else{
        	$arr=array(
                  'error'=>'1',
                  'info'=>'修改失败！'
        	  	);
        	 echo json_encode($arr);
        	 exit;
        }

     }   
          
       // $city=I('post.city');
       // $email=I('post.email');
       // $nickname=I('post.nickname');
       // $sex=I('post.sex');
       // $sign=I('post.sign');
       
       // 修改密码方法
        public function changepass(){
        	 // console.log(I('post.'))
         if (I('post.pass')!=I('post.repass')) {
           	 $arr=array(
                   'error'=>'1',
                   'info'=>'两次密码输入不正确，请重新输入！'
           	 	);
           	 echo json_encode($arr);
           	 exit;
           }else{
           	   $data['password']=md5(I('post.pass'));
               M('user')->where(array('id'=>$_SESSION['id']))->save($data);
              $arr=array(
                'error'=>'0',
                'info'=>'恭喜修改成功'
              	);  
              echo json_encode($arr);
              exit;
              }
        }

        // 修改头像方法
    public function upload(){
    	// var_dump($_FILES);
			        $upload = new \Think\Upload();// 实例化上传类
				    $upload->maxSize   =     3145728 ;// 设置附件上传大小
				    $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
				    $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
				    $upload->savePath  =     ''; // 设置附件上传（子）目录
				    // 上传文件 
				    $info   =   $upload->upload();
                        // var_dump($info);
				    if(!$info) {// 上传错误提示错误信息
				        echo $upload->getError();
				    }else{// 上传成功
              // var_dump($info);
              // exit();
				    	 $info = current($info);
				    	$path = "Uploads/".$info['savepath'].$info['savename'];    
				    	$res = M('user')->where(array('id'=>$_SESSION['id']))->save(array('face'=>$path));
					        if($res){
                    unlink($_SESSION['face']);
					        	$_SESSION['face']=$path;
					        	echo $path;
					        }else{
					        	echo 0;
					        }
					}
	}



	public function message(){
    
    //  $Verify = new \Think\Verify();
    //  $Verify->entry();
     
        $this->display();


	}
   public function sendemail()
    {

       $res=M('user')->find($_SESSION['id']);
       $email=$res['email'];
      $content = <<<str
      请点击此链接激活http://127.0.0.1/fly/index.php/home/setdata/activeEmail/id/{$_SESSION['id']}
str;
  xbsemail($email,'这个是一个fly社区激活的邮件',$content);
        

    }

    // 激活邮箱
    public function activeEmail(){
           $id=I('get.id');
           $_SESSION['id'];
           var_dump($id);
           var_dump($_SESSION['id']);

         if ($id==$_SESSION['id']){
           $this->error('激活成功',U('home/u/index'),3);
         }
 


    }

}